package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("adminCategoryController")
@RequestMapping ("/admin/category")
@Api( tags ="分类管理")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    // 新增分类
    @PostMapping
    @ApiOperation("新增分类")
    public Result addCategory(@RequestBody CategoryDTO categoryDTO) {
        // 实现新增分类的逻辑
        categoryService.save(categoryDTO);
        return Result.success();
    }

    // 分类分页查询
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> pageSort(CategoryPageQueryDTO categoryDTO){
        PageResult pageResult = categoryService.pageSort(categoryDTO);
        return Result.success(pageResult);
    }

    // 删除分类
    @DeleteMapping
    @ApiOperation("删除分类")
    public Result deleteCategory(Integer id) {
        // 实现删除分类的逻辑
        categoryService.deleteById(id);
        return Result.success();
    }

    // 修改分类
    @PutMapping
    @ApiOperation("修改分类")
    public Result editCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.editCategory(categoryDTO);
        return Result.success();
    }

    // 启用和禁用分类
    @PostMapping("/status/{status}")
    @ApiOperation("启用和禁用分类")
    public Result staOrst(@PathVariable Integer status, Long id){
        categoryService.staOrst(status,id);
        return Result.success();
    }

    // 根据类型查询分类
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> listCategory(Integer type){
        return Result.success(categoryService.listCategory(type));
    }
}
